import { createApp } from './app'
import './config'

export function runServer() {
    console.log('run server')
    const app = createApp()
    const port = (() => {
        let port = process.env.HTTP_PORT ? parseInt(process.env.HTTP_PORT) : 3000
        return isNaN(port) || port < 1 || port > 65535 ? 3000 : port
    })()
    app.listen(port, () => {
        console.log(`server runned at port ${port}`)
    })
}

if (require.main === module) {
    runServer()
}
